package com.data.modules.smzh.controller;


import cn.hutool.core.util.ObjectUtil;
import com.data.common.api.vo.Result;
import com.data.common.aspect.annotation.AutoLog;
import com.data.common.util.KamliClientUtil;
import com.data.modules.smzh.entity.Building;
import com.data.modules.smzh.entity.SmComAnnouncement;
import com.data.modules.smzh.entity.SmzhScreenMsg;
import com.data.modules.smzh.service.*;
import com.data.modules.smzh.vo.SmContactVo;
import com.data.modules.smzh.vo.SmDeviceVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.*;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @Author boot
 */

@RestController
@RequestMapping("/device")
@Api(tags="device")
@Slf4j
@SuppressWarnings("ALL")
public class DeviceManageController<stringWarnType> {


/*

	@ApiOperation(value="心跳", notes="心跳")
	@PostMapping(value = "/heart")
	public Result<?> addContact(@RequestBody SmContactVo smContactVo, HttpServletRequest req) {

		return oftenContactService.addContact(smContactVo,req);
	}

	@AutoLog(value = "命令执行结")
	@ApiOperation(value="命令执行结", notes="命令执行结")
	@PostMapping(value = "/cmdreport")
	public Result<?> add(@RequestBody SmComAnnouncement smComAnnouncement , HttpServletRequest req) {

		return smComAnnouncementService.smAddInfo(smComAnnouncement,req);
	}

	@AutoLog(value = "小区公告信息-删除")
	@ApiOperation(value="小区公告信息-删除", notes="小区公告信息-删除")
	@PostMapping(value = "/v1/deleteAdd")
	public Result<?> deleteAdd(@RequestBody SmComAnnouncement smComAnnouncement , HttpServletRequest req) {

		return smComAnnouncementService.smDeleteAdd(smComAnnouncement,req);
	}

	@AutoLog(value = "小区公告信息-查看")
	@ApiOperation(value="小区公告信息-查看", notes="小区公告信息-查看")
	@PostMapping(value = "/v1/queryAddInfo")
	public Result<?> queryAddInfo(@RequestBody SmComAnnouncement smComAnnouncement , HttpServletRequest req) {

		return smComAnnouncementService.smQueryAddInfo(smComAnnouncement,req);
	}

	@ApiOperation(value="查询门口机广告信息", notes="查询门口机广告信息")
	@GetMapping(value = "/v1/queryAdd")
	public Result<?> queryAdd(SmComAnnouncement smComAnnouncement,
								   HttpServletRequest req) {

		return smComAnnouncementService.searchAddInfo(smComAnnouncement,req);
	}

	@AutoLog(value = "推送门口机广告")
	@ApiOperation(value="推送门口机广告", notes="推送门口机广告")
	@PostMapping(value = "/v1/addPush")
	public Result<?> addPush(@RequestBody SmComAnnouncement smComAnnouncement) {

		String id =  smComAnnouncement.getId();
		SmComAnnouncement announcement = smComAnnouncementService.getById(id);
		if(ObjectUtil.isNotEmpty(announcement)){

			//通过项目主键查询出 绑定的 设备序列号推送消息
			List<String> serialNoList =  buildingService.queryDeviceInfoByProjectId(announcement.getComNo());

			serialNoList.parallelStream().forEach(x->{
				List list = Arrays.asList(announcement.getImage().split(","));
				Boolean flag=true;

				flag = KamliClientUtil.doPostpushMsgUr(x,"entDoorNotice",list);
				log.info("门口机广告推送消息序列号{},结果：{}",x,flag);
			});

		}

		return Result.ok(0,"操作成功");

	}

	@AutoLog(value = "物业公告-删除")
	@ApiOperation(value="物业公告-删除", notes="物业公告-删除")
	@PostMapping(value = "/v1/deleteNotic")
	public Result<?> deleteNotic(@RequestBody SmzhScreenMsg smComAnnouncement , HttpServletRequest req) {

		return smzhScreenMsgService.smDeleteNoticInfo(smComAnnouncement,req);
	}


	@AutoLog(value = "物业公告-查看")
	@ApiOperation(value="物业公告-查看", notes="物业公告-查看")
	@PostMapping(value = "/v1/queryNoticInfo")
	public Result<?> queryNoticInfo(@RequestBody SmzhScreenMsg smComAnnouncement , HttpServletRequest req) {

		return smzhScreenMsgService.smQueryNoticeInfo(smComAnnouncement,req);
	}

	@ApiOperation(value="查询物业公告信息", notes="查询物业公告信息")
	@GetMapping(value = "/v1/queryNoticeList")
	public Result<?> queryNoticeList(SmzhScreenMsg smComAnnouncement,
									 HttpServletRequest req) {

		return smzhScreenMsgService.searchNoticeListInfo(smComAnnouncement,req);
	}

	@AutoLog(value = "物业公告-添加")
	@ApiOperation(value="物业公告-添加", notes="物业公告-添加")
	@PostMapping(value = "/v1/noticAdd")
	public Result<?> noticAdd(@RequestBody SmzhScreenMsg smComAnnouncement , HttpServletRequest req) {

		return smzhScreenMsgService.smAddNoticInfo(smComAnnouncement,req);
	}

	@AutoLog(value = "物业公告-修改")
	@ApiOperation(value="物业公告-修改", notes="物业公告-修改")
	@PostMapping(value = "/v1/noticModity")
	public Result<?> noticModity(@RequestBody SmzhScreenMsg smComAnnouncement , HttpServletRequest req) {

		return smzhScreenMsgService.smModityNoticInfo(smComAnnouncement,req);
	}

	@AutoLog(value = "推送物业公告信息")
	@ApiOperation(value="推送物业公告信息", notes="推送物业公告信息")
	@PostMapping(value = "/v1/noticPush")
	public Result<?> noticPush(@RequestBody SmzhScreenMsg jsonObject) {

		String msgType = "sCreenMsg";
		String id =  jsonObject.getId();
		List list = new ArrayList();
		SmzhScreenMsg smzhScreenMsg = smzhScreenMsgService.getById(id);

		Map<String,Object> map = new HashMap<>();
		map.put("title",smzhScreenMsg.getTitle());
		map.put("type",smzhScreenMsg.getType());
		map.put("content",smzhScreenMsg.getRemakr());
		list.add(map);

		if(ObjectUtil.equals(2,smzhScreenMsg.getMsgClass())){//智慧屏公告
			msgType = "sCreenNotice";
		}

		List<String> projectlist = Arrays.asList(smzhScreenMsg.getProjectNo().split(","));

		List<Building> buildList= buildingService.queryBuildByProject(projectlist);

		String finalMsgTyp = msgType;
		buildList.stream().forEach(x->{
			//根据操作appId 和项目编号，查询建筑编号，循环推送消息
			KamliClientUtil.doPostpushMsgUr(x.getUniqueNo(), finalMsgTyp,list);
		});

		return Result.ok(0,"操作成功");
	}
*/


}
